package culton.android.clicklistener;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import culton.android.sms.SMSHandler;
import culton.android.util.Functions;

public class SMSClickListener implements OnClickListener {

	private String phoneNumber = null;
	private Intent mIntent;
	private Context mContext;
	private Bundle mBundle;
	
	public SMSClickListener(Context c, Intent i) {
		mContext = c;
		mIntent = i;
		mBundle = i.getExtras();
	}
	
	@Override
	public void onClick(View arg0) {
		String msg = createMsg();
        phoneNumber = mBundle.getString("tracker"); 
		SMSHandler.sendSMS(mContext, phoneNumber, msg);
		mContext.startActivity (mIntent);
	}
	
	private String createMsg() {		
		String find = mBundle.getString("find");
		
		String msg = "";
		
		if (find == "movies") {
			String cinemaName = Functions.removeSpecialCharacters(mBundle.getString("cinemaName"));
			msg = "CN:>M" + cinemaName;
			
		} else if (find == "showtimes") {
			String cinemaName = Functions.removeSpecialCharacters(mBundle.getString("cinemaName"));
			String movieName = Functions.removeSpecialCharacters(mBundle.getString("movieName"));
			msg = "CN:>S" + cinemaName + "+" + movieName;	
		}
		
		return msg;
	}
	
}
